
#pragma once

#ifndef __LOG_H__
#define __LOG_H__

#include "spdlog/spdlog.h"
#include "Common/Singleton.h"

#include <iostream>
#include <memory>

namespace NTrader
{

namespace spd = spdlog;

class Logger:public Singleton<Logger>
{
public:
	Logger()
	{
		console = spd::stdout_color_mt("console");
		daily_logger = spd::daily_logger_mt("daily_logger", "logs/NTrader", 3, 30);

		spd::set_pattern("[%H:%M:%S] [thread %t] %v");
		spd::set_level(spd::level::trace);
	}

	~Logger()
	{
		spd::drop_all();
	}

	std::shared_ptr<spd::logger> console;
	std::shared_ptr<spd::logger> daily_logger;
};

#if defined(_DEBUG)

#define TRADERLOG(x) Logger::GlobalInstance().console.get() != nullptr? Logger::GlobalInstance().console->trace(x):0==0;\
					Logger::GlobalInstance().daily_logger.get() != nullptr? Logger::GlobalInstance().daily_logger->trace(x):0==0;

/*#define TRADERLOG_DEBUG(x) spd::get("console") != nullptr? spd::get("console")->debug(std::string("[DEBUG] ") + x):0==0;\
							spd::get("daily_logger") != nullptr? spd::get("daily_logger")->debug(std::string("[DEBUG] ") + x):0==0;

#define TRADERLOG_INFO(x) spd::get("console") != nullptr? spd::get("console")->info(std::string("[INFO ] ") + x):0==0;\
							spd::get("daily_logger") != nullptr? spd::get("daily_logger")->info(std::string("[INFO ] ") + x):0==0;*/
#else

#define TRADERLOG(x) Logger::GlobalInstance().console.get() != nullptr? Logger::GlobalInstance().console->info(x):0==0;\
					Logger::GlobalInstance().daily_logger.get() != nullptr? Logger::GlobalInstance().daily_logger->info(x):0==0;

#endif
}

#endif